﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_Admin_CapNhatPhong : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layMaPhong();

            layTenPhong();

            layDienThoaiNoiBo();

            layDienThoaiNgoai();

            layFax();
        }
    }

    protected void layMaPhong()
    {
        string maPhongURL = Request.QueryString["MaPhong"];

        PhongBUS pBUS = new PhongBUS();

        string maPhong = pBUS.layMaPhong(maPhongURL);

        txtMaPhong.Text = maPhong;
    }

    protected void layTenPhong()
    {
        string maPhongURL = Request.QueryString["MaPhong"];

        PhongBUS pBUS = new PhongBUS();

        string tenPhong = pBUS.layTenPhong(maPhongURL);

        txtTenPhong.Text = tenPhong;
    }

    protected void layDienThoaiNoiBo()
    {
        string maPhongURL = Request.QueryString["MaPhong"];

        PhongBUS pBUS = new PhongBUS();

        string dienThoaiNoiBo = pBUS.layDienThoaiNoiBo(maPhongURL);

        txtDienThoaiNoiBo.Text = dienThoaiNoiBo;
    }

    protected void layDienThoaiNgoai()
    {
        string maPhongURL = Request.QueryString["MaPhong"];

        PhongBUS pBUS = new PhongBUS();

        string dienThoaiNoiNgoai = pBUS.layDienThoaiNgoai(maPhongURL);

        txtDienThoaiNgoai.Text = dienThoaiNoiNgoai;
    }

    protected void layFax()
    {
        string maPhongURL = Request.QueryString["MaPhong"];

        PhongBUS pBUS = new PhongBUS();

        string fax = pBUS.layFax(maPhongURL);

        txtFax.Text = fax;
    }

    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        {
            Phong pDTO = new Phong();
            pDTO.MaPhong = txtMaPhong.Text.ToUpper();
            pDTO.TenPhong = txtTenPhong.Text.ToUpper();
            pDTO.DienThoaiNoiBo = txtDienThoaiNoiBo.Text;
            pDTO.DienThoaiNgoai = txtDienThoaiNgoai.Text;
            pDTO.Fax = txtFax.Text;

            //Kiem tra rong
            if (pDTO.MaPhong.ToString() == string.Empty)
            {
                Alert.Show("Ma phong khong duoc rong");
                return;
            }

            if (pDTO.TenPhong.ToString() == string.Empty)
            {
                Alert.Show("Ten phong khong duoc rong");
                return;
            }

            if (pDTO.DienThoaiNoiBo.ToString() == string.Empty)
            {
                Alert.Show("Dien thoai noi bo khong duoc rong");
                return;
            }

            if (pDTO.DienThoaiNgoai.ToString() == string.Empty)
            {
                Alert.Show("Dien thoai ngoai khong duoc rong");
                return;
            }

            if (pDTO.Fax.ToString() == string.Empty)
            {
                Alert.Show("So fax khong duoc rong");
                return;
            }

            //Sua
            if (pDTO.MaPhong.ToString() != string.Empty && pDTO.TenPhong.ToString() != string.Empty && pDTO.DienThoaiNoiBo.ToString() != string.Empty && pDTO.DienThoaiNgoai.ToString() != string.Empty && pDTO.Fax.ToString() != string.Empty)
            {
                PhongBUS pBUS = new PhongBUS();

                string maPhongURL = Request.QueryString["MaPhong"];

                pBUS.suaPhong(pDTO, maPhongURL);

                Response.Redirect("ThamSoNguoiDung.aspx");
            }
        }
    }
    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("ThamSoNguoiDung.aspx");
    }
}